package com.hzit.manager.controller;

import com.hzit.common.util.R;
import com.hzit.manager.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wf
 * @since 2024-01-08
 */
@RestController
@RequestMapping("/brand")
@RefreshScope       // 修改配置后就不需要重启
public class BrandController {

	@Autowired
	private IBrandService brandService;
	@Value("${hzit.student.sname}")
	private String sname;
	@Value("${hzit.student.age}")
	private int age;
	@Autowired
	private StringRedisTemplate redisTemplate;
	//1. 查询品牌列表
	@GetMapping("/list")
	@PreAuthorize("hasAuthority('user:userlistxxx')")
	public R list(){
		return R.ok(brandService.list());
	}
	//2. 读取配置
	@GetMapping(value="/readConfig")
	public R readConfig(){
		Map map = new HashMap<>();
		map.put("sname",sname);
		map.put("age",age);
		//1. 读取redis
		String name = redisTemplate.opsForValue().get("name");
		map.put("name",name);
		return R.ok(map);
	}
}
